﻿using System.Collections.Generic;
using System.ComponentModel;
using System.Web.UI;
using Sunny.Core.DefinedData;

namespace Sunny.Control
{
    [DefaultProperty("Text")]
    [ToolboxData("<{0}:Combobox runat=server></{0}:Combobox>")]
    public class ComboBox : Ext.Net.ComboBox
    {
        public const string AllOptionValue = "-1";

        public void DataBind(IList<SListItem> items)
        {
            if (items != null)
            {
                foreach (var item in items)
                {
                    this.Items.Add(new Ext.Net.ListItem { Text = item.Text, Value = item.Value });
                }
            }
        }

        public void DataBind(IList<SListItem> items, bool isNeedAllOption)
        {
            if (items != null)
            {
                this.Items.Add(new Ext.Net.ListItem { Text = "All", Value = AllOptionValue });
                foreach (var item in items)
                {
                    this.Items.Add(new Ext.Net.ListItem { Text = item.Text, Value = item.Value });
                }
            }
        }
    }
}
